package com.collect.cameroon.zhiScene.zhiLogin.zhiFace.zhiLivenessUtil;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;

import com.collect.cameroon.zhiUtils.SPUtils;

import java.util.List;

public class LivenessIntentUtil {

    public static final int REQUEST_CODE_FACE = 233;

    //判断曾经调起失败flag
    public static final String LIVENESS_EXCEPTION_FLAG = "LIVE_EXC_FLAG";

    public LivenessIntentUtil() {
        this.isLivenessRandom = true;

    }

    public static LivenessIntentUtil getInstance() {
        return instance;
    }

    private static final LivenessIntentUtil instance = new LivenessIntentUtil();

    //动作列表
    public List<String> mLivenessList;

    //是否随机动作
    public boolean isLivenessRandom = true;

    //是否初始化成功
    private boolean hasGotToken = false;

    //是否检测成功
    public boolean isDetectSuccess = false;
    //检测成功为空字串，失败则是原因说明
    public String detectMsg = "";
    //如果检测成功，保存最佳图片的本地路径
    public String detectFilePath = "";
    //如果检测成功，保存最佳图片的bitmap
    public Bitmap detectFileImage = null;

    /**
     * 判断是否能调起ocr组件
     * 如果出现异常，则不调起ocr
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020-07-20 11:23
     */
    public boolean checkCanStartLiveness() {

        return false;
    }

    /**
     * 设置调起ocr异常标志
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020/8/5 11:00
     */
    public static void setLivenessRunException() {
        SPUtils.getInstance().put(LIVENESS_EXCEPTION_FLAG, "YES");
    }

    /**
     * 设置sdk配置参数
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020/8/10 15:59
     */
    public void setFaceConfig() {

    }

    /**
     * 判断是否已经初始化
     *
     * @type method
     * @author liwenjie
     * @creatTime 2020-07-20 11:23
     */
    public boolean checkTokenStatus() {
        return hasGotToken;
    }

    /**
     * 初始化SDK
     */
    public void startFaceRecog(final Activity activity, final int reqCode) {
        // 为了android和ios 区分授权，appId=appname_face_android ,其中appname为申请sdk时的应用名
        // 应用上下文
        // 申请License取得的APPID
        // assets目录下License文件名
        hasGotToken = true;

    }

    public void openFaceRecogUI(Activity activity, int reqCode) {
        if (!getInstance().checkTokenStatus()) {
            return;
        }
        try {
            Intent intent = new Intent(activity, FaceLivenessExpActivity.class);
            activity.startActivityForResult(intent, reqCode);
        } catch (Exception e) {
            e.printStackTrace();
            setLivenessRunException();
        }
    }
}
